﻿using System;
using System.Configuration;
using System.Data;
using System.Collections;
using System.IO;

using EHSubmit.Model;

namespace EHSubmit.Util
{
    /// <summary>
    ///  上传下载文件时用到的静态方法
    /// </summary>
    public class FileHelper
    {
        /// <summary>
        /// 上传根路径
        /// </summary>
        public static string UPLOAD_ROOT = "~/uploads/";

        /// <summary>
        /// 上传临时路径
        /// </summary>
        public static string UPLOAD_TMP_PATH = UPLOAD_ROOT + "temp/";

        /// <summary>
        /// 上传作业路径
        /// </summary>
        public static string UPLOAD_DEST_PATH = UPLOAD_ROOT + "homeworks/";

        /// <summary>
        /// 上传布置作业附件路径
        /// </summary>
        public static string UPLOAD_DEST_ATTACH_PATH = UPLOAD_ROOT + "goals/";

        /// <summary>
        /// 产生上传作业路径
        /// </summary>
        /// <param name="student">学生对象</param>
        /// <param name="goal">作业目标对象</param>
        /// <returns></returns>
        public static string GenerateGoalPath(User student, Goal goal)
        {
            string goalPath = UPLOAD_DEST_PATH + string.Format("{0}-{1}/", goal.ID, goal.Title.Trim());    // 形如：~uploads/homeworks/1-生产运作第1次作业/
            //string goalPath = @"c:/" + string.Format("{0}-{1}/", goal.ID, goal.Title);

            return goalPath;
        }


        /// <summary>
        /// 产生上传作业时的文件名
        /// </summary>
        /// <param name="student">学生对象</param>
        /// <param name="ext">后缀名</param>
        /// <returns>作业文件名</returns>
        public static string GenerateFileName(User student, string ext)
        {
            string fileName = string.Format("{0}-{1}{2}",student.ID.Trim(), student.Name.Trim() ,ext);   // 文件名形如：1-凌天蓝.doc
            return fileName;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="student"></param>
        /// <param name="goal"></param>
        /// <param name="ext"></param>
        /// <returns></returns>
        public static string GenerateFilePath(User student, Goal goal, string ext)
        {
            return GenerateGoalPath(student, goal) + GenerateFileName(student, ext);
        }




        /// <summary>
        /// 返回布置作业附件文件名
        /// </summary>
        /// <param name="goalName">作业名</param>
        /// <param name="ext">该文件后缀名</param>
        /// <returns>附件文件名</returns>
        public static string GenerateAttachFileName(string goalName, string ext)
        {
            string fileName = string.Format("{0}-作业说明{1}", goalName, ext);
            return fileName;
        }

        /// <summary>
        /// 返回作业附件路径(虚拟路径)
        /// </summary>
        /// <param name="teacher">教师对象</param>
        /// <returns>作业附件虚拟路径</returns>
        public static string GenerateAttachPath(User teacher)
        {
            
            return UPLOAD_DEST_ATTACH_PATH + string.Format("{0}-{1}/", teacher.ID.Trim(), teacher.Name.Trim());
        }
        
    }
}